"""
全国疫情可视化地图开发
"""

import json
from pyecharts.charts import Map

# 读取文件数据
f = open(r"C:\Users\Lenovo\OneDrive\桌面\三种图的案例\疫情.txt", "r", encoding="utf-8")
data = f.read()
f.close()

# 处理数据
# 转json为python
data_dict = json.loads(data)
# 获取要的数据
# 总
province_data_list = data_dict["areaTree"][0]["children"]
#横轴、纵轴（组装每个省份和确诊人数为元组，封装进列表中）
data_list = []
for province_data in province_data_list:
    province_name = province_data["name"]
    province_confirm = province_data["total"]["confirm"]
    data_list.append((province_name, province_confirm))
print(data_list)

# 生成图像
# 获取图表对象
map = Map()
#添加数据
map.add("各省份确诊人数", data_list, "china")
